package cn.wen.yinxiu.works.dao;

import cn.wen.yinxiu.works.entity.CommentEntity;
import cn.wen.yinxiu.works.vo.CommentVO;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * @ClassName: CommentDao
 * @Author 小飞
 * @Email coderwen22@163.com
 * @Date 2023-05-22 09:39:56
 * @Description: 作品的评论数据的Dao层
 */
@Component
@Mapper
public interface CommentDao extends BaseMapper<CommentEntity> {

    /**
     * 获取全部楼主的信息通过点赞数量和发布时间来排序
     *
     * @param worksId
     * @param status
     * @param isDeleted
     * @param page
     * @param pageSize
     * @return
     */
    List<CommentVO> findByWorksIdAndParentCommentNull(@Param("worksId") Long worksId,
                                                      @Param("status") Integer status,
                                                      @Param("isDeleted") Integer isDeleted,
                                                      @Param("page") Integer page,
                                                      @Param("pageSize") Integer pageSize);

    /**
     * 获取子评论
     *
     * @param commentId
     * @return
     */
    List<CommentVO> listTreeComment(@Param("commentId") Long commentId);

    /**
     * 获取用户在当前文章的点赞ID
     *
     * @param userId
     * @param worksId
     * @return
     */
    @MapKey("commentId")
    Map<Long, Long> getUserCommentLikeMap(@Param("userId") Long userId,
                                          @Param("worksId") Long worksId);

    /**
     * 评论点赞
     *
     * @param commendId
     * @param worksId
     * @param userId
     * @return
     */
    boolean deleteCommentLikeById(@Param("commentId") Long commendId,
                                  @Param("worksId") Long worksId,
                                  @Param("userId") Long userId);

    /**
     * 添加点赞评论
     *
     * @param commendId
     * @param worksId
     * @param userId
     * @return
     */
    boolean addCommentLikeById(@Param("commentId") Long commendId,
                               @Param("worksId") Long worksId,
                               @Param("userId") Long userId);
}
